package org.coast.mvc.logging;

import java.io.PrintWriter;

public class ConsoleLoghandler extends LogHandler {

    private static PrintWriter printWriter = new PrintWriter(System.out);

    //init
    @Override
    void configure() {
        setFormatter(new DefaultLogFormatter());
        setLogLevel(System.getProperty(LogConstants.LOG_LEVEL), LogLevel.INFO);
        printWriter.write(getFormatter().format(new LogRecord("coast log level set " + getLogLevel().getDesc())));
    }

    //输出
    @Override
    public synchronized void publish(LogRecord logRecord) {
        String msg = getFormatter().format(logRecord);
        printWriter.write(msg);
        printWriter.flush();
    }

    @Override
    boolean accept(String type) {
        return "console".equals(type.toLowerCase());
    }
}
